package thread;

public class SyncDemo4 {
    public static void main(String[] args) {
        Boo b = new Boo();
        new Thread(b::methodA).start();
        new Thread(b::methodB).start();
    }
}
class Boo{
    public synchronized void methodA(){
        Thread t = Thread.currentThread();
        System.out.println(t.getName()+":正在执行A方法...");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
        }
        System.out.println(t.getName()+":A方法执行完毕");
    }
    public void methodB(){
        synchronized (this){
            Thread t = Thread.currentThread();
            System.out.println(t.getName()+":正在执行B方法...");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t.getName()+":B方法执行完毕");
        }
    }
}
